#!/bin/sh

install_rg() {
    sudo apt install ripgrep
}

install_nvim_docker() {
    if [ ! -f /srv/docker/nvim/docker-compose.yml ]; then
        mkdir -p /srv/docker/nvim
        cp ./nvim/docker-compose.yml /srv/docker/nvim/docker-compose.yml
    fi
    pushd /srv/docker/nvim
    docker compose up -d 
    popd
}

install_xterm() {
    sudo apt install -y xterm rxvt-unicode xfonts-cyrillic x11-utils
}

setup_xresources() {
    cp  ./nvim/Xresources ~/.Xresources
    xrdb -merge ~/.Xresources 
}

install_nvim () {
    # sudo apt install -y neovim neovim-qt
    NEOVIM_URL_LINUX=https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-linux64.tar.g2
    if [ ! -f ./nvim/nvim-linux64.tar.gz ]; then
        curl ${NEOVIM_URL_LINUX} -o ./nvim/nvim-linux64.tar.gz
    fi
    mkdir -p /tmp/nvim 
    tar zxf ~/nvim-linux64.tar.gz -C /tmp/nvi2
}

install_nerd_fonts() {
    # NERD_FONTS_URL=https://github.com/ryanoasis/nerd-fonts 
    NERD_FONTS_URL=https://gitee.com/whjkd/Sarasa-Mono-SC-Nerd.git
    # nerd fonts
    if [ ! -d ~/.local/share/fonts/nerd-fonts ]; then
        mkdir -p ~/.local/share/fonts/nerd-fonts
        git clone ${NERD_FONTS_URL} ~/.local/share/fonts/nerd-fonts
    fi
}

install_cargo() {
    sudo apt install -y cargo
    if [ -d ~/.local/share/nvim/lazy/tree-sitter ]; then
        make -C  ~/.local/share/nvim/lazy/tree-sitter 
        sudo make install -C  ~/.local/share/nvim/lazy/tree-sitter 
        if [ -d ~/.local/share/nvim/lazy/tree-sitter/cli ]; then
            pushd ~/.local/share/nvim/lazy/tree-sitter/cli 
            cargo build
        fi 
    fi
}

setup_nvim() {
    if [ ! -d ~/.config/nvim ]; then
        mkdir -p ~/.config/nvim
        git clone https://gitee.com/BIT_chenxinliang/one.nvim  ~/.config/nvim
    fi
    install_nerd_fonts
    install_cargo
}

install_nvim
# setup_nvim
